#!/usr/bin/env python

from ga_class import GoogleAnalytics

def init ( l, admin = 0 ):
	g = GoogleAnalytics ( l )

	gaid = g.cfg.get ( "gaid", -1 ) 
		
	if gaid == -1 or g.cfg.get ( 'debug' ):
		return ''

	options = ''
	for k, v in g.cfg.get ( "options", {} ).iteritems (): 
		options += g.templates [ "push_option" ] % { "opt" : k, "val" : v }

	l.layman.add_js ( "modules/ga/js/ga.js" )
	l.layman.add_css ( "modules/ga/gfx/style.css" )

	tpl = g.templates.get ( "script" )

	#l.layman.add_js_code ( "ga.init();" )

	if admin and int ( admin ):
		l.layman.add_js ( "modules/ga/js/ga.admin.js" )
		l.layman.add_js_code ( "ga.admin.init();" )

	return tpl % { "gaid" : gaid, "options" : options }
